package jpademo.service;

import java.util.HashSet;
import java.util.Set;

import jpademo.model.Car;
import jpademo.model.User;
import jpademo.repository.UserRepository;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class UserService {

	
    @Autowired
    private UserRepository userRepository;
    
    public void one2manyDemo()
    {
        Car car1 = new Car();
        car1.setPrice(100);
        
        Car car2 = new Car();
        car2.setPrice(200);
        
        User user = new User();
        user.setName("Peter");

        car1.setUser(user);
        car2.setUser(user);
        
        Set<Car> cars = new HashSet<Car>();
        cars.add(car1);
        cars.add(car2);
        user.setCars(cars);        
        userRepository.save(user);
        userRepository.delete(user);
    }
}




    

   
